package com.gopay.common.user.manager.impl;

import com.gopay.common.domain.cust.CustPersonInfo;
import com.gopay.common.user.dao.CustPersonInfoQueryDAO;
import com.gopay.common.user.manager.CustPersonInfoQueryManager;
import com.gopay.common.util.NonrevEncr;
import com.gopay.common.util.pwd.UserPwdUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * CustPersonInfoQuery Manager实现
 * @CustPersonInfoQueryManagerImpl.java
 * @author liuxin
 * @2013-1-6 下午2:06:04  www.gopay.com.cn Inc.All rights reserved.
 */
@Service("custPersonInfoQueryManager")
public class CustPersonInfoQueryManagerImpl implements CustPersonInfoQueryManager {
    
    @Resource(name = "custPersonInfoQueryDao")
    private CustPersonInfoQueryDAO custPersonInfoQueryDao;

    @Override
    public CustPersonInfo get(Serializable id) {
        // TODO Auto-generated method stub
        return custPersonInfoQueryDao.find(CustPersonInfo.class, id);
    }

    @Override
    public List<CustPersonInfo> get(Map<Object, Object> paraMap) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<CustPersonInfo> getAll() {
        return custPersonInfoQueryDao.findAll(CustPersonInfo.class);
    }

    /**
     * 未注册认证的是手机号数量
     * @param mobileNo
     * @return
     */
    @Override
    public int getMobileNoCount(String mobileNo) {

        return custPersonInfoQueryDao.findMobileNo(mobileNo);
    }

    @Override
    public CustPersonInfo getByMobileNo(String mobileNo) {

        return custPersonInfoQueryDao.findByMobile(mobileNo);
    }

    @Override
    public int getByCertTypeAndCertNo(String certType, String certNo) {
        // TODO Auto-generated method stub
        return custPersonInfoQueryDao.findByCertTypeAndCertNo(certType, certNo);
    }

    @Override
    public CustPersonInfo getByEmail(String email) {
        return custPersonInfoQueryDao.findByEmail(email);
    }

    @Override
    public List<CustPersonInfo> getCustPersonOpen(String email) {
        return custPersonInfoQueryDao.findCustPersonOpen(email);
    }

    @Override
    public CustPersonInfo getByCustMob(String mobile) {
        return custPersonInfoQueryDao.findByCustMob(mobile);
    }

    @Override
    public CustPersonInfo getNoActiveCustByCustMob(String mobileNo) {
        return custPersonInfoQueryDao.getNoActiveCustByCustMob(mobileNo);
    }

    @Override
    public CustPersonInfo getNoActiveCustByCustEmail(String email) {
        return custPersonInfoQueryDao.getNoActiveCustByCustEmail(email);
    }

	@Override
	public CustPersonInfo getByCustId(String custId) {
		 return custPersonInfoQueryDao.getByCustId(custId);
	}


	
	@Override
	public void updateByCustId(CustPersonInfo custPersonInfo) {
		custPersonInfoQueryDao.update(custPersonInfo);
	}
	@Override
	 public CustPersonInfo findByCustMobmobile(String mobile) {
		 return custPersonInfoQueryDao.findByCustMobmobile(mobile);
		 
	}
	@Override
	 public CustPersonInfo findByCustMobmobileAllStatus(String mobile) {
		 return custPersonInfoQueryDao.findByCustMobmobileAllStatus(mobile);
		 
	}
	
	@Override
	public List<CustPersonInfo> getByCertNo(String custName, String certType, String certNo) {
	    return custPersonInfoQueryDao.findByCertNo(custName, certType, certNo);
	}

	@Override
	 public List<CustPersonInfo> findByCustListBycertNo(String certType,String certNo,String isRealNameCertify){
	 	return custPersonInfoQueryDao.findByCustListBycertNo(certType,certNo,isRealNameCertify);
	}
	@Override
	 public List<CustPersonInfo> findByCustListByPartnerId(String certNo,String name,String partnerCustId){
	 	return custPersonInfoQueryDao.findByCustListByPartnerId(certNo,name,partnerCustId);
	}
	
	 @Override
	 public CustPersonInfo findByMerCustId(String merId, String merCustId) {
		 List<CustPersonInfo> list = custPersonInfoQueryDao.findByMerCustId(merId, merCustId);
	     if(list != null  && !list.isEmpty()) {
	         return list.get(0);
	     }
	     return null;
	 }
	
    @Override
    public CustPersonInfo findByEmail(String email, String custName, String certType) {
        return custPersonInfoQueryDao.findByEmail(email,custName,certType);
    }
 
    @Override
    public CustPersonInfo findByCustMob(String mob, String custName, String certType) {
        return custPersonInfoQueryDao.findByCustMob(mob,custName,certType);
    }
	
    @Override
    public CustPersonInfo getByMobileWithoutStat(String mobile) {
        List<CustPersonInfo> list = custPersonInfoQueryDao.getByMobileWithoutStat(mobile);
        if(list != null  && !list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<CustPersonInfo> findByCNameAndCTypeAndCNoAndRNameIn(String custName, String certType, String certNo,
            List<String> isRealNameCertifyList) {
	    return custPersonInfoQueryDao.findByCNameAndCTypeAndCNoAndRNameIn(custName, certType, certNo, isRealNameCertifyList);
    }
	
	@Override
    public void setPersonNewPayPwd(StringBuilder sbNewPayPwd, CustPersonInfo person) {
        if(UserPwdUtil.isSHA1(person.getPayPwd())) {
            person.setPayPwd(NonrevEncr.sha512(sbNewPayPwd));
        } 
    }
    
    @Override
    public void setPersonNewMtPayPwd(StringBuilder sbNewMtPayPwd, CustPersonInfo person) {
        if(UserPwdUtil.isSHA1(person.getMtPayPwd())) {
            person.setMtPayPwd(NonrevEncr.sha512(sbNewMtPayPwd));
        } 
    }

    @Override
    public List<CustPersonInfo> getByMobileListWithoutStat(String mobile) {
        List<CustPersonInfo> list = custPersonInfoQueryDao.getByMobileWithoutStat(mobile);
        if(list != null  && !list.isEmpty()) {
            return list;
        }
        return null;
    }

    @Override
    public int findCustCountByCertNoWithoutCancelStat(String certType, String certNo) {
         List<CustPersonInfo> list = custPersonInfoQueryDao.findCustByCertNoWithoutCancelStat(certType,certNo);
         if(list != null && !list.isEmpty()) {
             return list.size();
         }
         return 0;
    }
}
